﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BHXH.Core.IService;
using FX.Core;
using BHXH.Core.Domain;

namespace BHXH.Frm.Frm
{
    public partial class ThongTinTaiKhoan : UserControl
    {
        private readonly IthongtincongtyService _thongtincongtySrv;
        private readonly ItaikhoanService _taikhoanSrv;
        string TenDangNhap = "";
        string matkhau = "";
        string hoten = "";
        string email = "";
        string congtyid = "";
        string taikhoanid = "";
        static string Masothue = "01696223732";
        public ThongTinTaiKhoan()
        {
            InitializeComponent();
            _thongtincongtySrv = IoC.Resolve<IthongtincongtyService>();
            _taikhoanSrv = IoC.Resolve<ItaikhoanService>();
            GetDonviByID(Masothue);
        }

        public ThongTinTaiKhoan(string TenDN, string MatKhau, string HoTen, string Email, string CongTyID, string TaiKhoanID)
        {
            InitializeComponent();
            _thongtincongtySrv = IoC.Resolve<IthongtincongtyService>();
            _taikhoanSrv = IoC.Resolve<ItaikhoanService>();
            TenDangNhap = TenDN;
            matkhau = MatKhau;
            hoten = HoTen;
            email = Email;
            congtyid = CongTyID;
            taikhoanid = TaiKhoanID;
            GetDonviByID(Masothue);
        }

        public void LoadThongTinTK()
        {
            lblTenDangNhap.Text = TenDangNhap;
            lblTenChuTaiKhoan.Text = hoten;
            lblTenGoiSanPham.Text = "";
            lbl22.Text = "";
        }

        public void GetDonviByID(string MaSoThue)
        {

            var ThongtinDV = _thongtincongtySrv.GetDonViByID(MaSoThue);
            var ThongtinTK = _thongtincongtySrv.GetDonVi_TaiKhoan();
            
            foreach (var item in ThongtinTK)
            {

                lblTenDangNhap.Text = item.TaiKhoan;
                lblTenChuTaiKhoan.Text = item.thongtincongty.TenCongTy;
                lblTenGoiSanPham.Text = "";
                lblThoiHanSuDung.Text = "";
            }
        }

        

        private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e)
        {

        }

       
        private void lklThayDoiTTTK_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string HoTen;
            string TenDangNhap;
            string MatKhau;
            string Email;
            string CongTyID;
            string taikhoanID;
            ThayDoiThongTinTK frmThayDoiTTTK = Application.OpenForms.OfType<ThayDoiThongTinTK>().FirstOrDefault();
            if (frmThayDoiTTTK == null)
            {
                var TTDV_TK = _thongtincongtySrv.GetDonVi_TaiKhoan();
                foreach (var item in TTDV_TK)
                {

                    HoTen = item.thongtincongty.TenCongTy;
                    TenDangNhap = item.TaiKhoan;
                    MatKhau = item.MatKhau;
                    Email = item.thongtincongty.Email;
                    CongTyID = item.CongTyId.ToString();
                    taikhoanID = item.ID.ToString();
                    frmThayDoiTTTK = new ThayDoiThongTinTK(TenDangNhap, MatKhau, HoTen, Email, CongTyID, taikhoanID);
                    frmThayDoiTTTK.LoadThongTinTK();
                    frmThayDoiTTTK.Show();
                }

            }
            else
            {
                frmThayDoiTTTK.BringToFront();
            }
        }
    }
}
